<!DOCTYPE html>
<html  xmlns:th="http://www.thymeleaf.org">
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<META HTTP-EQUIV="expires" CONTENT="0">
<head>
    <link rel="stylesheet" th:href="@{/adminlte/layui/css/layui.css}"  media="all"/>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<div class="demoTablePubProduct">
    <div class="layui-inline" style="margin-left: 0px"> 生产单号：</div>
    <div class="layui-inline" style="width: 220px">
        <input class="layui-input"  id="productNumSearchPubProduct" autocomplete="off" style="width: 200px;height: 25px" placeholder="请输入生产单号"/>
    </div>
    产品名称：
    <div class="layui-inline" style="width: 220px">
        <!--<input class="layui-input"  id="goodsNameSearchPubProduct" autocomplete="off" style="width: 200px;height: 25px" placeholder="请输入产品名称"/>-->
        <select id="goodsNameSearchPubProduct" style="width: 200px;height: 25px">
            <option value="">请选择产品名称</option>
            <option th:each="goodsNameP1:${goodsNameP}" th:value="${goodsNameP1.dataname}" th:text="${goodsNameP1.dataname}"></option>
        </select>
    </div>
    产品规格:
    <div class="layui-inline" style="width: 220px">
       <!-- <input class="layui-input"  id="goodsSpecificationsSearchPubProduct" autocomplete="off" style="width: 200px;height: 25px" placeholder="请输入产品规格"/>-->
        <select id="goodsSpecificationsSearchPubProduct" style="width: 200px;height: 25px">
            <option value="">请选择产品规格</option>
            <option th:each="specificationsP1:${specificationsP}" th:value="${specificationsP1.dataname}" th:text="${specificationsP1.dataname}"></option>
        </select>
    </div>
    <div class="layui-inline" style="margin-left: -15px">操作员名称：</div>
    <div class="layui-inline" style="width: 220px;">
        <input class="layui-input"  id="operatorSearchPubProduct" autocomplete="off" style="width: 200px;height: 25px" placeholder="请输入操作员名称"/>
    </div>
    <button class="layui-btn layui-btn-sm" data-type="reload">查询</button><br/>
    起始日期：
    <div class="layui-inline" style="width: 220px">
        <input class="layui-input"  id="startDateSearchPubProduct" autocomplete="off" style="width: 200px;height: 25px" placeholder="请选择起始日期"/>
    </div>
    截止日期：
    <div class="layui-inline" style="width: 220px">
        <input class="layui-input"  id="endDateSearchPubProduct" autocomplete="off" style="width: 200px;height: 25px" placeholder="请选择截止日期"/>
    </div>
</div>
<div id="add-mainPp" style="display: none;">
    <div class="my-form">
        <div class="layui-form-item my-form-item" style="margin-top: 10px">
            <div class="layui-inline">
                <label class="layui-form-label" style="width: 170px"><p style="color: red;display: inline">※</p>生产单号</label>
                <div class="layui-input-inline">
                    <input type="text" id="productNumAdd" name="productNumAdd" lay-verify="" autocomplete="off" class="layui-input" placeholder="请输入生产单号" onkeyup="value=value.replace(/[^\d]/g,'')" onblur="productNumAdd()" >
                    <p id="productNumAddP" style="color: red; display: none" >生产单号已被使用</p>
                </div>
            </div>
        </div>
        <div class="layui-form-item my-form-item" style="margin-top: 10px">
            <div class="layui-inline">
                <label class="layui-form-label" style="width: 170px">阀门编号</label>
                <div class="layui-input-inline">
                    <input type="text" id="vavleNumAdd" name="vavleNum" lay-verify="" autocomplete="off" class="layui-input" placeholder="请输入阀门编号" onkeyup="value=value.replace(/[^\d]/g,'')" onblur="vavleNumAddSerch()" >
                    <p id="vavleNumAddP" style="color: red; display: none" >阀门编号已被使用</p>
                </div>
            </div>
        </div>
        <div class="layui-form-item my-form-item">
            <div class="layui-inline">
                <label class="layui-form-label" style="width: 170px"><p style="color: red;display: inline">※</p>主板编号</label>
                <div class="layui-input-inline">
                    <input type="text" id="mainBoardNumAdd" name="mainBoardNum" lay-verify="" autocomplete="off" class="layui-input" placeholder="请输入主板编号" onkeyup="value=value.replace(/[^\d]/g,'')" onblur="mainBoardNumAddSerch()" >
                    <p id="mainBoardNumAddP" style="color: red; display: none" >主板编号已被使用</p>
                </div>
            </div>
        </div>
        <div class="layui-form-item my-form-item">
            <div class="layui-inline">
                <label class="layui-form-label" style="width: 170px">备注</label>
                <div class="layui-input-inline">
                    <input type="text" id="remarksAdd" name="remarks" lay-verify="" autocomplete="off" class="layui-input" placeholder="请输入备注">
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="toolbarDemoPub">
    <div class="layui-btn-container" >
        <button class="layui-btn layui-btn-sm" lay-event="add"  >装配</button>
        <button class="layui-btn layui-btn-sm" lay-event="check"  >测试</button>
        <button class="layui-btn layui-btn-sm" lay-event="clear"  >清表</button>
        <button class="layui-btn layui-btn-sm" lay-event="clearEx"  >清异常</button>
        <button class="layui-btn layui-btn-sm" lay-event="pubRefresh"  >刷新</button>
        <!--<button class="layui-btn layui-btn-sm" lay-event="update" id="update" >修改</button>-->
        <!--<button class="layui-btn layui-btn-sm" lay-event="upload" id="upload" >导入</button>-->
        <button class="layui-btn layui-btn-sm" lay-event="delete"  >删除</button>
    </div>
</script>
<table class="layui-table" lay-data="{url:'/production/pubProductDate', page:true, id:'idTestPub',toolbar:'#toolbarDemoPub',defaultToolbar:['filter', 'print','exports'] }" lay-filter="demoPub">
    <thead>
    <tr>
        <th lay-data="{type:'checkbox', fixed: 'left'}" rowspan="2"></th>

        <th lay-data="{align:'center'}" colspan="10">生产订单信息</th>
        <th lay-data="{align:'center'}" colspan="6">阀门信息</th>
        <th lay-data="{align:'center'}" colspan="5">控制主板信息</th>
        <th lay-data="{align:'center'}" colspan="12">通讯主板信息</th>
        <th lay-data="{align:'center'}" colspan="6">485主板信息</th>
        <th lay-data="{align:'center'}" colspan="5">工艺</th>
    </tr>
    <tr>
        <th lay-data="{field:'productNum', width:180}" >生产单号</th>
        <th lay-data="{field:'goodsName', width:150}" >产品名称</th>
        <th lay-data="{field:'confValveModel', width:150}" >配置类型</th>
        <th lay-data="{field:'code', width:150}" >执行状态</th>
        <th lay-data="{field:'specifications',width:150}" >产品规格</th>
        <th lay-data="{field:'pressure',width:150}" >使用压力</th>
        <th lay-data="{field:'nums',width:150}" >数量</th>
        <th lay-data="{field:'operator',width:150}" >制单人</th>
        <th lay-data="{field:'operatorTime',width:180}" >制单时间</th>
        <th lay-data="{field:'remarks',width:150}" >备注</th>
        <th lay-data="{field:'valveSupplier', width:150 }">阀门供应商</th>
        <th lay-data="{field:'valveNUms', width:180 }">阀门编号</th>
        <th lay-data="{field:'valveName', width:150}">阀门名称</th>
        <th lay-data="{field:'valveSpecifications', width:150}">阀门规格</th>
        <th lay-data="{field:'intakeDirection', width:150}">进气方向</th>
        <th lay-data="{field:'vavleProductDate', width:150}">生产日期</th>
        <th lay-data="{field:'controlMainboardSupplier', width:150}">控制主板供应商</th>
        <th lay-data="{field:'controlMainBoardNums', width:180}">控制主板编号</th>
        <th lay-data="{field:'controlMainboardName', width:150 }">控制主板名称</th>
        <th lay-data="{field:'controlMainboardSpecifications', width:150}">控制主板规格</th>
        <th lay-data="{field:'controlMainBoardProductDate', width:150}">生产日期</th>
        <!--<th lay-data="{field:'version', width:150}">程序版本</th>-->
        <th lay-data="{field:'telMainBoardSupplier', width:150}">通信主板供应商</th>
        <th lay-data="{field:'telMainBoardNums', width:180}">通信主板编号</th>
        <th lay-data="{field:'telMainBoardName', width:150}">通信主板名称</th>
        <th lay-data="{field:'telMainBoardSpecifications', width:150}">通信主板规格</th>
        <th lay-data="{field:'telType', width:150}">通信方式</th>
        <th lay-data="{field:'cardNum', width:150}">卡号</th>
        <th lay-data="{field:'iMSI', width:150}">IMSI号</th>
        <th lay-data="{field:'iMEI', width:150}">IMEI号</th>
        <th lay-data="{field:'iCCID', width:150}">ICCID号</th>
        <th lay-data="{field:'activeTime', width:150}">激活日期</th>
        <th lay-data="{field:'shutdownTime', width:150}">截止日期</th>
        <th lay-data="{field:'telMainBoardProductDate', width:150}">生产日期</th>
        <th lay-data="{field:'fourSupplier', width:150}">485供应商</th>
        <th lay-data="{field:'fourMainBoardNums', width:180}">485主板编号</th>
        <th lay-data="{field:'fourMainBoardName', width:150}">485主板名称</th>
        <th lay-data="{field:'fourSpecifications', width:150}">485主板规格</th>
        <th lay-data="{field:'telProtocol', width:150}">通信协议</th>
        <th lay-data="{field:'fourMainBoardProductDate', width:150}">生产日期</th>
        <th lay-data="{field:'assembler', width:150}">装配人</th>
        <th lay-data="{field:'productDate', width:180}">装配日期</th>
        <th lay-data="{field:'tester', width:150}">检测人</th>
        <th lay-data="{field:'testDate', width:180}">检测日期</th>
        <th lay-data="{field:'testRemarks', width:150}">备注</th>
    </tr>
    </thead>
</table>

<script th:src="@{/adminlte/layui/layui.all.js}" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use('table', function(){
        var table = layui.table;
        //监听表格复选框选择
        table.on('checkbox(demoPub)', function(obj){
            console.log(obj)
        });
        //监听工具条
        table.on('tool(demoPub)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                layer.msg('ID：'+ data.id + ' 的查看操作');
            } else if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                /*layer.alert('编辑行：<br/>'+ JSON.stringify(data))*/

            }
        });
        //监听头工具栏事件
        table.on('toolbar(demoPub)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id)
                ,data = checkStatus.data//获取选中的数据
                ,deList=[1];
            data.forEach(function (n,i) {
                deList.push(n.ids)
            });
            deList.push(2);
            switch(obj.event){
                case 'add':
                    layer.open({
                        type:1,
                        title:'添加',
                        btnAlign: 'c',
                        area: ['450px', '380px'],
                        btn:['保存','取消'],
                        content: $("#add-mainPp"),
                        success:function(){
                            top.$("#remarksAdd").val("");
                           top.$("#vavleNumAdd").val("");
                            top.$("#mainBoardNumAdd").val("");
                            top.$("#productNumAdd").val("");
                        },
                        yes:function(index,layero){
                            var testRemarks =top.$("#remarksAdd").val();
                            var valveNUms =top.$("#vavleNumAdd").val();
                            var controlMainBoardNums =top.$("#mainBoardNumAdd").val();
                            var productNum1 =top.$("#productNumAdd").val();
                            if(controlMainBoardNums==""||productNum1==""){
                             /*   alert("您还有必填项未填哦！")valveNUms==""||*/
                                layer.msg('您还有必填项未填哦！', {
                                    btnAlign: 'c',
                                    time: 3000, //20s后自动关闭
                                    btn: ['确定']
                                });
                            }else {
                                $.ajax({
                                    //几个参数需要注意一下
                                    type: "POST",//方法类型
                                    dataType: "json",//预期服务器返回的数据类型
                                    url: "/production/addPubProduct" ,//url
                                    data: {testRemarks:testRemarks,valveNUms:valveNUms,controlMainBoardNums:controlMainBoardNums,productNum:productNum1},
                                    success: function (result) {
                                        console.log(result);//打印服务端返回的数据(调试用)
                                        if (result.success >0) {
                                            layer.msg('操作成功', {
                                                btnAlign: 'c',
                                                time: 3000, //20s后自动关闭
                                                btn: ['确定']
                                            });
                                            table.reload('idTestPub');
                                        }else{
                                            layer.msg('操作失败', {
                                                btnAlign: 'c',
                                                time: 3000, //20s后自动关闭
                                                btn: ['确定']
                                            });
                                        }
                                    },
                                    error : function() {
                                        alert("异常！");
                                    }
                                });

                                layer.close(index);
                            }

                        },
                        btn2:function (index) {
                            layer.close(index);
                        },
                        end:function(){
                            table.reload('idTestPub');
                        }
                    });
                    break;
                case 'check':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    } else if(data.length > 1){
                        layer.msg('只能同时测试一个');
                    } else {
                        var id =checkStatus.data[0].ids;
                        var productNum =checkStatus.data[0].productNum;
                        layer.confirm('确定测试？',{btn: ['确定', '取消'], title: "提示"},function(index){
                            $.ajax({
                                //几个参数需要注意一下
                                type: "POST",//方法类型
                                dataType: "json",//预期服务器返回的数据类型
                                url: "/production/updatePubProduct" ,//url
                                data: {ids:id,productNum:productNum},
                                success: function (result) {
                                    if (result.success>0&&result.cc>0) {
                                        layer.msg('操作成功', {
                                            btnAlign: 'c',
                                            time: 3000, //20s后自动关闭
                                            btn: ['确定']
                                        });
                                        table.reload('idTestPub')
                                    }else if(result.cc==0){
                                        layer.msg('未找到通讯编号信息', {
                                            btnAlign: 'c',
                                            time: 3000, //20s后自动关闭
                                            btn: ['确定']
                                        });
                                    }else{

                                        layer.msg('操作失败', {
                                            btnAlign: 'c',
                                            time: 3000, //20s后自动关闭
                                            btn: ['确定']
                                        });
                                    }
                                },
                                error : function() {
                                    alert("异常！");
                                }
                            });
                            layer.close(index);
                        });
                    }
                    break;
                case 'clear':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    } else if(data.length > 1){
                        layer.msg('只能同时清除一个');
                    } else {
                        var id =checkStatus.data[0].ids;
                        var productNum =checkStatus.data[0].productNum;
                        layer.confirm('确定清表？',{btn: ['确定', '取消'], title: "提示"},function(index){
                            $.ajax({
                                //几个参数需要注意一下
                                type: "POST",//方法类型
                                dataType: "json",//预期服务器返回的数据类型
                                url: "/production/clear" ,//url
                                data: {ids:id,productNum:productNum},
                                success: function (result) {
                                    if (result.success>0&&result.cc>0) {
                                        layer.msg('操作成功', {
                                            btnAlign: 'c',
                                            time: 3000, //20s后自动关闭
                                            btn: ['确定']
                                        });
                                        table.reload('idTestPub')
                                    }else if(result.cc==0){
                                        layer.msg('未找到通讯编号信息', {
                                            btnAlign: 'c',
                                            time: 3000, //20s后自动关闭
                                            btn: ['确定']
                                        });
                                    }else{

                                        layer.msg('操作失败', {
                                            btnAlign: 'c',
                                            time: 3000, //20s后自动关闭
                                            btn: ['确定']
                                        });
                                    }
                                },
                                error : function() {
                                    alert("异常！");
                                }
                            });
                            layer.close(index);
                        });
                    }
                    break;
                case 'clearEx':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    } else if(data.length > 1){
                        layer.msg('只能同时操作一个');
                    } else {
                        var id =checkStatus.data[0].ids;
                        var productNum =checkStatus.data[0].productNum;
                        layer.confirm('确定清异常？',{btn: ['确定', '取消'], title: "提示"},function(index){
                            $.ajax({
                                //几个参数需要注意一下
                                type: "POST",//方法类型
                                dataType: "json",//预期服务器返回的数据类型
                                url: "/production/clearEx" ,//url
                                data: {ids:id,productNum:productNum},
                                success: function (result) {
                                    if (result.success>0&&result.cc>0) {
                                        layer.msg('操作成功', {
                                            btnAlign: 'c',
                                            time: 3000, //20s后自动关闭
                                            btn: ['确定']
                                        });
                                        table.reload('idTestPub')
                                    }else if(result.cc==0){
                                        layer.msg('未找到通讯编号信息', {
                                            btnAlign: 'c',
                                            time: 3000, //20s后自动关闭
                                            btn: ['确定']
                                        });
                                    }else{

                                        layer.msg('操作失败', {
                                            btnAlign: 'c',
                                            time: 3000, //20s后自动关闭
                                            btn: ['确定']
                                        });
                                    }
                                },
                                error : function() {
                                    alert("异常！");
                                }
                            });
                            layer.close(index);
                        });
                    }
                    break;
                case 'pubRefresh':
                    table.reload('idTestPub');
                    break;
                case 'delete':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    } else {
                        layer.confirm('确定删除',{btn: ['确定', '取消'], title: "提示"},function(index){
                            $.ajax({
                                //几个参数需要注意一下
                                type: "POST",//方法类型
                                dataType: "json",//预期服务器返回的数据类型
                                url: "/production/dtletePubProduct" ,//url
                                data: {deList:JSON.stringify(deList)},
                                success: function (result) {
                                    if (result.success>0) {
                                        layer.msg('操作成功', {
                                            btnAlign: 'c',
                                            time: 3000, //20s后自动关闭
                                            btn: ['确定']
                                        });
                                        table.reload('idTestPub')
                                    }else{
                                        layer.msg('操作失败', {
                                            btnAlign: 'c',
                                            time: 3000, //20s后自动关闭
                                            btn: ['确定']
                                        });
                                    }
                                },
                                error : function() {
                                    alert("异常！");
                                }
                            });
                            layer.close(index);
                        });
                    }
                    break;
            }
        });
        var $ = layui.$, active = {
            /*     getCheckData: function(){ //获取选中数据
                     var checkStatus = table.checkStatus('idTest')
                         ,data = checkStatus.data;
                     layer.alert(JSON.stringify(data));
                 }
                 ,getCheckLength: function(){ //获取选中数目
                     var checkStatus = table.checkStatus('idTest')
                         ,data = checkStatus.data;
                     layer.msg('选中了：'+ data.length + ' 个');
                 }
                 ,isAll: function(){ //验证是否全选
                     var checkStatus = table.checkStatus('idTest');
                     layer.msg(checkStatus.isAll ? '全选': '未全选')
                 }
                 ,*/
            reload:function () {
                var productNum = $("#productNumSearchPubProduct").val();
                var goodsName = $("#goodsNameSearchPubProduct").val();
                var specifications = $("#goodsSpecificationsSearchPubProduct").val();
                var operator = $("#operatorSearchPubProduct").val();
                var startDate = $("#startDateSearchPubProduct").val();
                var endDate = $("#endDateSearchPubProduct").val();

                table.reload('idTestPub',{
                    url:'/production/searchPubProduct',
                    where:{productNum:productNum,goodsName:goodsName,specifications:specifications,operator:operator,startDate:startDate,endDate:endDate}  ,
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                })

            }
        };

        $('.demoTablePubProduct .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        laydate.render({
            elem: '#startDateSearchPubProduct' //指定元素
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#endDateSearchPubProduct' //指定元素
            ,type: 'datetime'
        });
    });
    layui.use(['upload'],function(){
        var $ = layui.jquery,
            upload = layui.upload;
//指定允许上传的文件类型
        upload.render({
            elem: '#upload'
            ,url: '/production/uploadPubProduct'
            ,accept: 'file' //普通文件
            ,exts: 'xlsx' //只允许上传excel文件
            ,done: function(res){
                if(res.code == 0){ //上传成功
                    layer.msg(res.msg);
                    table.reload('idTestPub');
                }else{
                    layer.msg('上传失败');
                }
            }
            ,error: function(index, upload){
                layer.msg('上传失败');
            }
        });
    });
    function productNumAdd() {
        var productNum=$("#productNumAdd").val();
        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: "/production/productNum" ,//url
            data: {productNum:productNum},
            success: function (result) {
                console.log(result);//打印服务端返回的数据(调试用)
                if (result.exist >0) {
                    $("#productNumAddP").show();
                    $("#productNumAdd").val("");
                }else{
                    $("#productNumAddP").hide();
                }
            }/*,
            error : function() {
                alert("异常！");
            }*/
        });

    }
    function vavleNumAddSerch() {
        var vavleNumAdd=$("#vavleNumAdd").val()
        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: "/production/vavleNum" ,//url
            data: {vavleNum:vavleNumAdd},
            success: function (result) {
                console.log(result);//打印服务端返回的数据(调试用)
                if (result.exist >0) {
                    $("#vavleNumAddP").show();
                    $("#vavleNumAdd").val("");
                }else{
                    $("#vavleNumAddP").hide();
                }
            }/*,
            error : function() {
                alert("异常！");
            }*/
        });

    }
    function mainBoardNumAddSerch() {
        var mainBoardNumAdd=$("#mainBoardNumAdd").val()
        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: "/production/mainBoardNum" ,//url
            data: {mainBoardNum:mainBoardNumAdd},
            success: function (result) {
                console.log(result);//打印服务端返回的数据(调试用)
                if (result.exist >0) {
                    $("#mainBoardNumAddP").show();
                    $("#mainBoardNumAdd").val("");
                }else{
                    $("#mainBoardNumAddP").hide();
                }
            }/*,
            error : function() {
                alert("异常！");
            }*/
        });

    }
    var unSelected = "#999";
    var selected = "#333";
    $(function () {
        $("select").css("color", unSelected);
        $("option").css("color", selected);
        $("select").change(function () {
            var selItem = $(this).val();
            if (selItem == $(this).find('option:first').val()) {
                $(this).css("color", unSelected);
            } else {
                $(this).css("color", selected);
            }
        });
    })
</script>

</body>
</html>